package com.tom.org.controller;

import com.tom.basic.utils.AjaxResult;
import com.tom.basic.utils.PageList;
import com.tom.org.domain.Logininfo;
import com.tom.org.query.LogininfoQuery;
import com.tom.org.service.ILogininfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "部门的API",description="部门相关的CRUD功能")
@RestController
@RequestMapping("/logininfo")
public class LogininfoController {
    @Autowired
    private ILogininfoService LogininfoServiceImpl;
    /**
    * @Title: 根据id查询
    * @Description: TODO
    * @Author: LT
    * @Version: 1.0
    * @Date:
    * @Parameters:
    * @Return
    */
    @ApiOperation(value = "通过ID查询" )
    @GetMapping("/{id}")
    public Logininfo loadById(@ApiParam(value = "ID属性",required = true) @PathVariable("id")Long id){
       return LogininfoServiceImpl.loadById(id);
   }
    /**
    * @Title: 查询所有
    * @Description: TODO
    * @Author: LT
    * @Version: 1.0
    * @Date:
    * @Parameters:
    * @Return
    */
   @GetMapping
   public List<Logininfo> loadAll(){
       return LogininfoServiceImpl.loadAll();
   }
   /**
   * @Title: 高级查询
   * @Description: TODO
   * @Author: LT
   * @Version: 1.0
   * @Date:
   * @Parameters:
   * @Return
   */
   @PostMapping
    public PageList<Logininfo> queryData(@RequestBody LogininfoQuery logininfoQuery) {
        return LogininfoServiceImpl.queryData(logininfoQuery);
    }
    /**
    * @Title: 根据id删除
    * @Description: TODO
    * @Author: LT
    * @Version: 1.0
    * @Date:
    * @Parameters:
    * @Return
    */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id")Long id){
       try {
           LogininfoServiceImpl.remove(id);
           return AjaxResult.me();
       } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
       }
    }
    /**
    * @Title: 增加和删除
    * @Description: TODO
    * @Author: LT
    * @Version: 1.0
    * @Date:
    * @Parameters:
    * @Return
    */
    @PutMapping
    public AjaxResult updateOrAdd(@RequestBody Logininfo logininfo) {
        try {
            if (logininfo.getId() == null){
                LogininfoServiceImpl.save(logininfo);
            } else {
                LogininfoServiceImpl.update(logininfo);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }
    }

    @PatchMapping
    public AjaxResult batchDel(@RequestBody Long ids[]){
        try {
            LogininfoServiceImpl.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }

    }
}
